#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e4 + 5;

int n, n2, num, w, h;
struct Line {
  int l, r, h, w;
  bool operator<(Line line) const {
    if (h != line.h) return h < line.h;
    return w < line.w;
  }
} lines[N];
int x[N];
int mx[N << 2], tag[N << 2];
void build(int p, int l, int r) {
  mx[p] = 0, tag[p] = 0;
  if (l + 1 == r) return;
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid, r);
}
void pushup(int p) { mx[p] = max(mx[p << 1], mx[p << 1 | 1]) + tag[p]; }
void addtag(int d, int p) {
  tag[p] += d;
  mx[p] += d;
}
void update(int L, int R, int d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p);
    return;
  }
  int mid = (l + r) >> 1;
  if (L < mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid, r);
  pushup(p);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> w >> h;
    n2 = n * 2;
    rep(i, 1, n) {
      int x1, x2, y, l;
      cin >> x1 >> y >> l;
      x2 = x1 + w;
      x[i] = x1;
      x[i + n] = x2;
      lines[i] = Line{x1, x2, y, l};
      lines[i + n] = Line{x1, x2, y + h, -l};
    }
    sort(x + 1, x + n2 + 1);
    sort(lines + 1, lines + n2 + 1);
    num = unique(x + 1, x + n2 + 1) - x - 1;
    rep(i, 1, n2) {
      lines[i].l = lower_bound(x + 1, x + num + 1, lines[i].l) - x;
      lines[i].r = lower_bound(x + 1, x + num + 1, lines[i].r) - x;
    }
    build(1, 1, num);
    int ans = 0;
    rep(i, 1, n2) {
      update(lines[i].l, lines[i].r, lines[i].w, 1, 1, num);
      ans = max(ans, mx[1]);
    }
    cout << ans << endl;
  }
  return 0;
}